import os

from funasr import AutoModel
from funasr.utils.postprocess_utils import rich_transcription_postprocess


class ASRModule:
    def __init__(self,config):
        self.current_dir = os.path.dirname(os.path.abspath(__file__))
        self.model_dir = os.path.join(self.current_dir, "model")
        self.model = AutoModel(
            model = self.model_dir,
            vad_kwargs = {"max_single_segment_time":30000},
            device = "cpu",
            disable_update=True,
            hub="hf",
        )
    def audio_file_to_text(self, file_path):
        res = self.model.generate(
            input = file_path,
            language = "auto",
        )
        text = res[0]["text"]
        return rich_transcription_postprocess(text)

if __name__ == "__main__":
    funasr = FunAsr()
    res = funasr.audio_file_to_text("test.wav")
    print(res)